﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DBAccess;
using SSPharma.Common;
using SSPharma.Model;
using System.Data.Common;

namespace SSPharma.Biz.DanhMuc
{
    class BizDanhMucTaiKhoan
    {

        public DataTable ft_GetDataDanhMucDonViTheoMa(string Ma)
        {
            StringBuilder strSQL = new StringBuilder();
            strSQL.Append(" SELECT * from HT_DM_DonVi where MaDonVi = @Ma");
            SQLServer.Param[] Params = new SQLServer.Param[1];
            Params[0] = new SQLServer.Param("@Ma", Ma);
            return Global.DataFactory.GetDataTable(strSQL.ToString(), Params);
        }
        public DataTable fs_LayCauTrucTable()
        {
            StringBuilder strSQL = new StringBuilder();
            strSQL.Append(" SELECT * from HT_DM_DonVi where 1=2");
            return Global.DataFactory.GetDataTable(strSQL.ToString());
        }
        public void sg_SaveDataDanhMucDonVi(DataTable dt)
        {
            string query = "Select * from HT_DM_DonVi where 1 = 2";
            Global.DataFactory.RunSaveData(dt, query);
        }

        public IList<DonVi> fl_DSDanhMuc_DonVi()
        {
            List<DonVi> items = new List<DonVi>();
            DonVi item;
            StringBuilder strSQL = new StringBuilder(300);
            strSQL.Append("SELECT MaDonVi,TenDonVi");
            strSQL.Append(" FROM HT_DM_DonVi");
            strSQL.Append(" ORDER BY ID_SQ");
            using (DbDataReader dataReader = Global.DataFactory.Reader(strSQL.ToString()))
            {
                if (dataReader.HasRows)
                {
                    while (dataReader.Read())
                    {
                        item = new DonVi();
                        item.Id =  dataReader.IsDBNull(0) ? string.Empty : dataReader.GetString(0);
                        item.Name = dataReader.IsDBNull(1) ? string.Empty : dataReader.GetString(1);
                        items.Add(item);
                    }
                }
            }

            return items;
        }
        /// <summary>
        /// User: TAMNN 23/07/2014
        /// Mục đích: lấy danh sách theo danh mục
        /// </summary>
        /// <returns></returns>
        public DataTable ft_GetListdata(IList<string> list, string Orderby)
        {
            string str = string.Join(",", list.ToArray());
            StringBuilder strSQL = new StringBuilder();
            strSQL.Append(" SELECT ");
            strSQL.Append(str);
            strSQL.Append(" from HT_DM_DonVi with(nolock)");
            strSQL.Append(!string.IsNullOrEmpty(Orderby) ? (" order by " + Orderby) : "");
            return Global.DataFactory.GetDataTable(strSQL.ToString());
        }



    }
}
